package simulateOS.management.process;

import javafx.beans.property.SimpleDoubleProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import simulateOS.entity.Process;
import simulateOS.utils.RuntimeTimer;

import javax.annotation.Resource;

//@Component
public class TimeRunner implements Runnable{

    private Process process;

    private Double create_time;

    private Double now_time;

    private boolean isRun = true;

    private RuntimeTimer runtimeTimer;

    public TimeRunner(Process process,RuntimeTimer runtimeTimer) {
        this.process = process;
        this.runtimeTimer = runtimeTimer;
        this.create_time = runtimeTimer.getCurTime();
    }

    @Override
    public void run() {
        while(isRun) {
            now_time = runtimeTimer.getCurTime() - create_time;
            Double runningTime = now_time - create_time;
            this.process.setRunningTime(runningTime);
        }
    }

    public void destroy() {
        now_time = runtimeTimer.getCurTime();
        this.process.setDestroyTime(now_time);
        Double runningTime = now_time - create_time;
        this.process.setRunningTime(runningTime);
        this.isRun = false;
    }

    public Double getNow_time() {
        return now_time;
    }

}
